<?php

	//http://localhost/simp.php?get=avatar&p=oscar&type=small&uid=66665062
	//http://localhost/simp.php?get=ip-port&c=debug
	$url = '';
	
	if ( $_GET['get'] == 'avatar' ) {
	
		if ( $_GET['p'] == 'oscar' ) {
		
			 $url = 'http://api.icq.net/expressions/get?f=native&type=buddyIcon&t=' . $_GET['uid'] ;
			
		} else if ( $_GET['p'] == 'mrim' ) {
		
			list( $user, $domain ) = explode( '@', $_GET['uid'] );
			list( $domain_name, $zone ) = explode( '.', $domain );
			
			$url = 'http://avt.foto.mail.ru/'. $domain_name .'/'. $user .'/_mrimavatar';
		} else
			exit;
		
		$data = file_get_contents( $url );

		if ( $data == null ) {
			exit;
		}
			
		$src_img = imagecreatefromstring( $data );
		
		$dst_w = imagesx($src_img);
		$dst_h = imagesy($src_img);
		
		if( $_GET['type'] == 'small' ) {
			$dst_w = 24;
			$dst_h = 24;
		} else if ( imagesx($src_img) > 64 && imagesy($src_img) > 64 ) {
			$dst_w = 64;
			$dst_h = 64;
		}
		$dst_img = imagecreatetruecolor( $dst_w, $dst_h );
		
		imagecopyresampled( $dst_img, $src_img, 0, 0, 0, 0, $dst_w, $dst_h, imagesx($src_img), imagesy($src_img));

		header('Content-type: image/png');
		
		imagepng($dst_img, $outfile );
		imagedestroy( $src_img );
		imagedestroy( $dst_img );
	
	
		//echo $outfile;
	} else
		exit;
	
/*	
'http://api.icq.net/expressions/get?f=native&type=buddyIcon&t=66665062'
'http://avt.foto.mail.ru/bk/ahmetshin_rushan/_mrimavatar'
*/
?>
